package cn.ven.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
//
@TableName("t_user")
public class MyUser implements UserDetails {
    @TableId(type = IdType.AUTO)
    private Integer id; //用户id
    private String username; //用户名 唯一索引
    private String password; //密码
    private String nickname; //网名
    private String role; //角色
    private Integer closed; //角色是否可见
    private String picture; //用户头像
    private Integer focusNum; //关注的数量
    private Integer focusedNum; //粉丝的数量



    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }


    public String getUsername() {
        return this.username;
    }

    public void setUsername(String username) {
        this.username = username;
    }
        @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        String aa[] =this.role.split(",");
        List<SimpleGrantedAuthority> lst =new ArrayList<>();
        for (String s:aa){
            SimpleGrantedAuthority sga = new SimpleGrantedAuthority(s.trim());
            System.out.println("s===="+s);
            lst.add(sga);
        }
        return lst;
    }

    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getNickname() {
        return this.nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public Integer getClosed() {
        return closed;
    }

    public void setClosed(Integer closed) {
        this.closed = closed;
    }

    public String getPicture() {
        return picture;
    }

    public void setPicture(String picture) {
        this.picture = picture;
    }

    public Integer getFocusNum() {
        return focusNum;
    }

    public void setFocusNum(Integer focusNum) {
        this.focusNum = focusNum;
    }

    public Integer getFocusedNum() {
        return focusedNum;
    }

    public void setFocusedNum(Integer focusedNum) {
        this.focusedNum = focusedNum;
    }

    @Override
    public String toString() {
        return "MyUser{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", nickname='" + nickname + '\'' +
                ", role='" + role + '\'' +
                ", closed=" + closed +
                ", picture='" + picture + '\'' +
                ", focusNum=" + focusNum +
                ", focusedNum=" + focusedNum +
                '}';
    }
}
